package respotion

import (
	"week41/service/inits"
	"week41/service/modle"
)

func Login(name string, password string) (result modle.User, err error) {
	err = inits.DB.Where("name=?", name).Where("password=?", password).Find(&result).Error
	if err != nil {
		return
	}
	return result, err
}

func Register(name string, password string) (result modle.User, err error) {
	result = modle.User{
		Name:     name,
		Password: password,
	}
	err = inits.DB.Create(&result).Error
	if err != nil {
		return modle.User{}, err
	}
	return result, nil
}

func List() (result []*modle.User, err error) {
	err = inits.DB.Find(&result).Error
	if err != nil {
		return []*modle.User{}, err
	}
	return result, nil
}
